<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * OA_Router, sub class of CI_Router.
 * 
 * Override method: _parse_routes. Only list in $route 
 * which in file .application/routes.php can be process, 
 * else show 404 page
 * 
 */

/*
 * $Id: OA_Router.php 46 2011-08-11 13:11:46Z leikou@163.com $
 */


class OA_Router extends CI_Router
{
	/**
	 *  Parse Routes
	 *
	 * This function matches any routes that may exist in
	 * the config/routes.php file against the URI to
	 * determine if the class/method need to be remapped.
	 *
	 * @access	private
	 * @return	void
	 */
	function _parse_routes()
	{	
		// Turn the segment array into a URI string
		$uri = implode('/', $this->uri->segments);

		// Is there a literal match?  If so we're done
		if (isset($this->routes[$uri]))
		{
			return $this->_set_request(explode('/', $this->routes[$uri]));
		}

		// Loop through the route array looking for wild-cards
		foreach ($this->routes as $key => $val)
		{
			// Convert wild-cards to RegEx
			$key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));

			// Does the RegEx match?
			if (preg_match('#^'.$key.'$#', $uri))
			{
				// Do we have a back-reference?
				if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE)
				{
					$val = preg_replace('#^'.$key.'$#', $val, $uri);
				}

				return $this->_set_request(explode('/', $val));
			}
		}

		// If we got this far it means we didn't encounter a
		// matching route. If none segments specified, we'll 
		//set the site default route, or show 404 page.		
		if(empty($this->uri->segments))
		{	
			$this->_set_request($this->uri->segments);
		}
		else
		{
			show_404($uri);
		}	
	}
}




/* End of file: OA_Router.php */
/* Location: ./application/core/OA_Router.php */